package com.duoec.doc.dto.response;

import java.io.Serializable;

/**
 * @param <T> 响应数据类型
 * @author xuwenzhen
 */
public class BaseResponse<T> implements Serializable {
    /**
     * 状态码，0表示成功，其他表示失败
     *
     * @demo 0
     */
    private Integer code;

    /**
     * 返回数据
     */
    private T data;

    /**
     * 错误信息
     */
    private String msg;

    public static <D> BaseResponse<D> success(D data) {
        BaseResponse<D> resp = new BaseResponse<>();
        resp.setData(data);
        resp.setCode(0);
        return resp;
    }

    public static <D> BaseResponse<D> error(int code, String msg) {
        BaseResponse<D> response = new BaseResponse<>();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
